package com.uxbee.service;

import java.util.ArrayList;
import java.util.List;

import com.uxbee.pojo.HtmlData;

// 递归获取整站全部链接
public class LinkLoad {

	// 整站链接
	public static List<HtmlData> resHtmlDataList = new ArrayList<HtmlData>();

	// 递归获取整站全部链接
	public static void load(HtmlData htmlData, LinkFilter filter) {
		// 获取单个页面链接
		List<HtmlData> htmlDataList = LinkParser.extracLinks(htmlData,
				new LinkFilter() {

					public boolean accept(String mainUrl, String url) {
						int index = url.indexOf(mainUrl);
						if (index == -1) {
							return false;
						}
						else {
							return true;
						}

					}
				});
		// 页面不为空的场合获取下级链接
		if (htmlDataList != null && htmlDataList.size() != 0) {
			System.out.println("获取到" + htmlDataList.size() + "个链接");
			resHtmlDataList.addAll(htmlDataList);
			for (int i = 0; i < htmlDataList.size(); i++) {
				LinkLoad.load(htmlDataList.get(i), filter);
			}
		}
	}
}
